package com.tsc.user.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.tsc.user.entity.UserInfo;
import com.tsc.user.mapper.UserInfoMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: chentl
 * @Date: 2025/08/15/17:31
 * @Description:
 */
@Service
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

//    @Autowired
//    private RedisTemplate<String, Object> redisTemplate;

    @Override
    public List<UserInfo> selectUserInfoList(int status) {
        LambdaQueryWrapper wrapper = new LambdaQueryWrapper<UserInfo>().eq(UserInfo::getStatus, status);
        List<UserInfo> userInfoList = userInfoMapper.selectList(wrapper);
        return userInfoList;
    }

    @Override
    public UserInfo insertUserInfo(UserInfo userInfo) {
        userInfo.setCreateTime(new Date());
        userInfo.setUpdateTime(new Date());
        userInfoMapper.insert(userInfo);
        return userInfo;
    }

    @Override
    public UserInfo updateUserInfo(UserInfo userInfo) {
        userInfoMapper.updateById(userInfo);
        return userInfo;
    }

    @Override
    public int deleteUserInfo(Integer id) {
        int result = userInfoMapper.deleteById(id);
        return result;
    }

    @Override
    public UserInfo selectUserInfo(String userId) {
        return userInfoMapper.selectOne(new LambdaQueryWrapper<UserInfo>().eq(UserInfo::getUserId, userId));
    }

    @Override
    public UserInfo selectUserInfoByName(String userName) {
        return userInfoMapper.selectOne(new LambdaQueryWrapper<UserInfo>().eq(UserInfo::getUserName, userName));
    }
}
